﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

//using System.Web;
using System.Web.Services;
using System.Data;
using System.ComponentModel;
using System.Reflection;


namespace UCWebpart.WEB
{
    [System.Web.Script.Services.ScriptService]
    public partial class ShowInfor : System.Web.UI.Page
    {
        string uName;

        UserInfo userInfo;
        int uLevel = 0;
        List<MTR_Admin> AdminInfoList;
        string bookingPerson;
        string participants;//与会人
        string bookingState;

        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.Params["id"];
            hdf.Value = id;

            if (Request.Params["isApprove"] != null)
            {
                string startApprove = Request.Params["isApprove"];
                if (startApprove == "isApprove")
                {
                    HiddenField1.Value = "isApprove";
                    return;
                }
            }
            else
            {
                userInfo = (UserInfo)Session["userInfo"];
                AdminInfoList = userInfo.AdminInfoList;
                foreach (MTR_Admin ma in AdminInfoList)
                {
                    uLevel = uLevel > Convert.ToInt32(ma.adminLevel) ? uLevel : Convert.ToInt32(ma.adminLevel);
                }
                using (var mtr_resEn = new meetingroomManagementEntities())
                {
                    var cls = (from c in mtr_resEn.MTR_bas_BookingManage
                               where c.bookingID == id
                               select c
                               ).SingleOrDefault<MTR_bas_BookingManage>();
                    bookingPerson = cls.bookingPerson;
                    participants = cls.participants;
                    bookingState = cls.bookingState.ToString();
                }
                uName = Session["userName"].ToString();

                string[] str = participants.Split(';');
                for (int i = 0; i < str.Length; i++)
                {
                    if (uName == str[i].Split('@')[0] || bookingState=="1")
                    {
                        //当前用户是与会人或者正在审批中
                        HiddenField1.Value = "ableToSee";
                    }
                }
                //预定人和当前用户一样
                if (uName == bookingPerson)
                {
                    HiddenField1.Value = "ableToUpdate";
                }
                //当前用户是管理员
                else if (uLevel >= 1)
                {
                    HiddenField1.Value = "ableToSee";
                }
                else
                {
                    Response.Write("<script>alert('您当前的权限无法查看此次预定信息'); </script>");
                    //Response.Redirect("BookingManage.aspx", false);
                    //返回上一页 <script window.location.href='UserManage.aspx'</script>
                    //Response.Write("<script language=javascript>history.go(-2);</script>"); Response.Write("<script language=javascript>history.go(-2);</script>");
                    Response.Write("<script language=javascript>history.go(-1);</script>");
                }
            }
        }

        [WebMethod]
        public string showEveInfor(string bookingId)
        {
            var mtr = new meetingroomManagementEntities();
            var query = (from bm in mtr.MTR_bas_BookingManage
                         from bs in mtr.MTR_bas_BookingSchedul
                         from m in mtr.MTR_bas_Meetingroom
                         where bm.Meetingroom == m.mtrId && bm.bookingID == bs.planId &&
                         bm.bookingID == bookingId
                         select new
                         {
                             participants = bm.participants,
                             meetingTheme = bm.meetingTheme,
                             Meetingroom = bm.Meetingroom,
                             bookingPerson = bm.bookingPerson,
                             mtrAddress = m.mtrAddress,
                             mtrName = m.mtrName,
                             specialRequestFirst = bm.specialRequestFirst,
                             specialRequestSecond = bm.specialRequestSecond,
                             meetingStartDate = bs.meetingStartDate,
                             startTime = bs.startTime,
                             meetingEndDate = bs.meetingEndDate,
                             endTime = bs.endTime,
                             meetingAbstract = bm.meetingAbstract
                         });
            return "11";
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }


}